<template>
    <div v-if="ishead">
        <template v-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
            <van-field :id="itemdata.sField" required disabled :value="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
        </template>
        <template v-else-if="itemdata.lMustInput === '1'">
            <van-field placeholder="请选择" :id="itemdata.sField" required clearable :value="itemdata.value" :label="itemdata.sTitle" right-icon="location-o" @click-right-icon="openMap(itemdata, item)" />
        </template>
        <template v-else-if="itemdata.lCanInput === '0'">
            <van-field :id="itemdata.sField" disabled :value="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
        </template>
        <template v-else>
            <van-field placeholder="请选择" :id="itemdata.sField" clearable :value="itemdata.value" :label="itemdata.sTitle" right-icon="location-o" @click-right-icon="openMap(itemdata, item)" />
        </template>
    </div>
    <div v-else>
        <template v-if="itemdata.lCanOutput === '0'">
            <input type="hidden" :id="itemdata.sField" v-model="itemdata.value" />
        </template>
        <template v-else-if="itemdata.lMustInput === '1' && itemdata.lCanInput === '0'">
            <van-field :id="itemdata.sField" required disabled :value="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
        </template>
        <template v-else-if="itemdata.lMustInput === '1'">
            <van-field placeholder="请选择" :id="itemdata.sField" required clearable :value="itemdata.value" :label="itemdata.sTitle" right-icon="location-o" @click-right-icon="openMap(itemdata, item)" />
            <div class="amap-page-container1">
                <el-amap vid="amapDemo" ref="map" :center="center" :zoom="zoom" :events="events"></el-amap>
            </div>
        </template>
        <template v-else-if="itemdata.lCanInput === '0'">
            <van-field :id="itemdata.sField" disabled :value="itemdata.value" :label="itemdata.sTitle" :error-message="itemdata.errormsg" />
        </template>
        <template v-else>
            <van-field placeholder="请选择" :id="itemdata.sField" clearable :value="itemdata.value" :label="itemdata.sTitle" right-icon="location-o" @click-right-icon="openMap(itemdata, item)" />
            <div class="amap-page-container1">
                <el-amap vid="amapDemo" ref="map" :center="center" :zoom="zoom" :events="events"></el-amap>
            </div>
        </template>
    </div>
</template>
<script>
export default {
  props: {
    item: {
      type: Object,
      required: false
    },
    jsondata: {
      type: Object,
      required: false
    },
    itemdata: {
      type: Object,
      required: false
    },
    ishead: {
      type: Boolean,
      default: false
    },
    index: {
      type: Number,
      required: false
    }
  },
  methods: {
    openMap (data, item) {
      let name = ''
      //  alert(JSON.stringify(item.groupvalue))
      let gv = item.groupvalue
      //  alert(gv.length)
      for (let i = 0; i < gv.length; i++) {
        if (gv[i].sField === 'sname') {
          name = gv[i].value
          break
        }
      }
      // alert("name::" + name)
      this.$router.push({
        name: 'map4common',
        params: {
          sval: this.jsondata.head,
          svalmap: data,
          curName: name
        }
      })
    }
  }
}
</script>
